/**********************************************************************
 Copyright (C) 2010 Teppo Eeva

 This file is part of Arithmetic Game.
 For more information, see <http://code.google.com/p/arithmetic-game/>

 Arithmetic Game is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.

 Arithmetic Game is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with Arithmetic Game.  If not, see <http://www.gnu.org/licenses/>.
 **********************************************************************/

#include <QtGui/QApplication>
#include "mainwindow.h"
#include "arithgame.h"
#include <QTranslator>
#include <QLibraryInfo>
#include <QLocale>
#include <QDebug>
#include <QEvent>
#include <QSettings>
#include <arithgame.h>
#include <QString>
#include <QLibraryInfo>

int main(int argc, char *argv[])
{
    QApplication arithGame(argc, argv);
    arithGame.setApplicationName("Arithmetic_game");

    QTranslator arithGameTranslator;
    QTranslator qtTranslator;
    const QString &qtTrPath = QLibraryInfo::location(QLibraryInfo::TranslationsPath);

    QSettings settings(settingsName);
    QLocale::Language lang = (QLocale::Language)(settings.value("settings/language").toInt());
    if (lang == 0)
    {
        qDebug() << "No language stored - Select default language based on system language";
        lang = QLocale::system().language() == QLocale::Finnish ? QLocale::Finnish : QLocale::English;
    }

    if (lang == QLocale::Finnish)
    {
        qDebug() << "Localize - FI";
        arithGameTranslator.load("arithgame_fi",arithGame.applicationDirPath());
        qtTranslator.load("qt_fi",qtTrPath);
    }
    else
    {
        qDebug() << "Localize - EN";
        arithGameTranslator.load("arithgame_en",arithGame.applicationDirPath());
        qtTranslator.load("qt_en",qtTrPath);
    }
    arithGame.installTranslator(&arithGameTranslator);
    arithGame.installTranslator(&qtTranslator);

    MainWindow w;

#ifndef Q_OS_SYMBIAN
    w.show();
#else // Q_OS_SYMBIAN
    w.showMaximized();
#endif // Q_OS_SYMBIAN

    return arithGame.exec();
}

